<?php


namespace app\shop\command;


use app\enterprise\model\Message;
use app\shop\model\order\OrderModel;
use yunwuxin\cron\Task;
use think\console\Command;
use think\console\Input;
use think\console\Output;

class OrderFinalizeRemind extends Task
{
    protected function configure()
    {
        $this->everyMinute();
    }

    protected function execute()
    {
        //获取当前时间
        $currentTime = time();
        // 查询条件
        $orders = OrderModel::whereIn('order_status', [0, 1])
            ->where('delivery_time', '<', $currentTime)
            ->where('remind_time', 0)
            ->field('id,design_id,order_name,user_id')
            ->select();
        foreach ($orders as $v) {
            OrderModel::update([
                'remind_time' => time(),
            ], ['id' => $v['id']]);
            $message = Message::createMessageData($v['user_id'], $v['design_id'], 'system', '订单已到交稿时间');
            $message['del_user'] = $v['user_id'];
            $message['order_id'] = $v['id'];
            Message::sendMessage($message);
            print "****************交稿提醒执行完毕******************\n";
        }
    }
}